package dk.mirasola.systemtraining.user.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import dk.mirasola.systemtraining.user.client.i18n.UserEntryPointTexts;


public class UserEntryPoint implements EntryPoint {
    interface UserEntryPointUiBinder extends UiBinder<Widget,UserEntryPoint>{}
    private static UserEntryPointUiBinder uiBinder = GWT.create(UserEntryPointUiBinder.class);
    private static UserEntryPointTexts texts = GWT.create(UserEntryPointTexts.class);

    @UiField
    HTML topHeader;
    @UiField
    HTML biddingSetsHeader;
    @UiField
    HTML distributionFilterHeader;
    @UiField
    Image dk;
    @UiField
    Image gb;

    private static class LocaleClickHandler implements ClickHandler {
        private String locale;

        private LocaleClickHandler(String locale) {
            this.locale = locale;
        }

        @Override
        public void onClick(ClickEvent clickEvent) {
            Window.Location.assign(Window.Location.createUrlBuilder().setParameter("locale", locale).buildString());
        }
    }

    public void onModuleLoad() {
        RootLayoutPanel.get().add(uiBinder.createAndBindUi(this));
        topHeader.setHTML(texts.topHeader());
        biddingSetsHeader.setHTML(texts.biddingSetsHeader());
        distributionFilterHeader.setHTML(texts.distributionFilterHeader());

        dk.addClickHandler(new LocaleClickHandler("da"));
        gb.addClickHandler(new LocaleClickHandler("en"));
    }
}
